/**
 * CJJ's JavaScript Kit
 *
 * @type      : class
 * @version   : v0.1 build 20090826
 * @memo      : none 
 * -----------------------------------
 * Copyright (c) cjj http://www.imcjj.com
 */
function JSKit(path){
	/*private member variable*/
	var _rT=null, _iM=[], _p=path, _D=document;

	/*private method*/
	function $(selector) {
		var args=this.arguments;
		var name, results=null, pO=_D, s=selector.replace(/\s*/g,"");
		var firstChar=s.substr(0,1);

		if(args&&args.length>1){pO=args[1]};
		switch(firstChar){
		case '.':
			var element,elements =pO.getElementsByTagName("*");
			var j=0;

			results=[];
			name=s.replace('.',"");

			for (var i=0;element=elements[i];i++){
				if(element.className&&element.className==name){results[j++]=element;} 
			}

			break;
		case '#':
			name=s.replace('#',"");

			if(_D.getElementById){results=_D.getElementById(name)}
			else if(_D.all){results=_D.all[name]}
			else if(_D.layers){results=_D.layers[name]};

			break;
		default:/*getElementById*/
			if(_D.getElementsByTagName){results=pO.getElementsByTagName(name)};

			break;
		}

		return results
	};

	function $VP(){
		return {
			"width":window.innerWidth != null ? window.innerWidth : _D.documentElement && _D.documentElement.clientWidth ? _D.documentElement.clientWidth : _D.body != null ? _D.body.clientWidth : null,
			"height":window.innerHeight != null? window.innerHeight : _D.documentElement && _D.documentElement.clientHeight ? _D.documentElement.clientHeight : _D.body != null? _D.body.clientHeight : null,
			"top":window.pageYOffset!=undefined ? window.pageYOffset : _D.documentElement && _D.documentElement.scrollTop ? _D.documentElement.scrollTop : _D.body.scrollTop ? _D.body.scrollTop : 0,
			"left":	window.pageXOffset != undefined ? window.pageXOffset : _D.documentElement && _D.documentElement.scrollLeft ? _D.documentElement.scrollLeft : _D.body.scrollLeft ? _D.body.scrollLeft : 0
		};
	}/*end "getViewPoint"*/

	/*public method*/
    JSKit.prototype.Import=function(file,isClass){
        var s, jk=this, lC;

        if(!_iM[file]){_iM[file]={"script":s,state:"loading","classname":file.substring(file.lastIndexOf("/")+1,file.length)};
        if(_iM[file].state=="loaded"){return;}
		
		lC=_iM[file].classname;
		s=_D.createElement("script");
		s.src =_p+file+".js";
		s.onreadystatechange=function(){
			if(this.readyState=='complete'||this.readyState=='loaded'){


				if(lC=="Import"||lC=="Run"){return};
				if (isClass){jk[lC]=eval(lC);}

				_iM[file].state="loaded";
				s.onreadystatechange=null;
				return
			}
		};

		s.onload=function(){
			if(lC=="Import"||lC=="Run"){return};
			if(isClass!=false){jk[lC]=eval(lC);}

			_iM[file].state="loaded";
			s.onload=null;
		};

		_D.getElementsByTagName("head")[0].appendChild(s);
    };/*end of Import*/

	JSKit.prototype.Run=function(code){
		var loaded=true, jk=this;

		for(importFile in _iM){
			if(_iM[importFile]=="loading"){loaded=false;break}
		};

		if(!loaded){_rT=setTimeout(function(){jk.Run(code)},200); return};
		if(_rT){clearTimeout(_rT)};
		if(typeof(code)=="function"){code()}
	};/*end of "Run"*/

	JSKit.prototype.Remove=function(file){
		_D.getElementsByTagName("head")[0].removeChild(_iM[file].script);

		if(_iM[file].classname){eval(_iM[file].classname+"=null;");}

		_iM[file]=null;
	}
}